package com.qiyuesuo.sdk.sample;

import com.qiyuesuo.sdk.v2.SdkClient;
import com.qiyuesuo.sdk.v2.bean.*;
import com.qiyuesuo.sdk.v2.json.JSONUtils;
import com.qiyuesuo.sdk.v2.request.ContractDraftRequest;
import com.qiyuesuo.sdk.v2.response.SdkResponse;

/**
 * @Auther: Tangzhiqiang
 * @Date: 2020/3/8 0008 16:49
 * @Description: 类描述！！！！
 */
public class TestTem {
    public static void main(String[] args) {

        // 初始化sdkClient
        String serverUrl = "https://openapi.qiyuesuo.cn";
        String accessKey = "Mi6E4lLXjj";
        String accessSecret = "XanHE3KZb7jU61JA5H3CJdk8Uv7da0";
        SdkClient sdkClient = new SdkClient(serverUrl, accessKey, accessSecret);
// 合同基本参数
        Contract contract = new Contract();
        contract.setSubject("测试合同");
        contract.setCategory(new Category(2674186439108858315L));
        contract.setBizId("666");
        contract.setSend(false);

// 对接方
        Signatory signatory2 = new Signatory();
        signatory2.setTenantName("测试合同");
        signatory2.setTenantType("COMPANY");
        signatory2.setReceiver(new User("唐志强", "18229781528", "MOBILE"));
        signatory2.setSerialNo(1);
        Action action = new Action("COMPANY", 1);
        signatory2.addAction(action);
        // 个人
        Signatory signatory1 = new Signatory();
        signatory1.setTenantName("唐志强");
        signatory1.setTenantType("PERSONAL");
        signatory1.setReceiver(new User("唐志强", "18229781528", "MOBILE"));
        signatory1.setSerialNo(2);
// 设置签署方
        contract.addSignatory(signatory2);
        contract.addSignatory(signatory1);
        contract.addTemplateParam(new TemplateParam("p1", "value1"));
// 创建合同
        ContractDraftRequest request = new ContractDraftRequest(contract);
        String response = sdkClient.service(request);
        SdkResponse<Contract> responseObj = JSONUtils.toQysResponse(response, Contract.class);
// 返回结果
        if(responseObj.getCode() == 0) {
            Contract result = responseObj.getResult();
            System.out.println("创建合同成功，合同ID:{}"+ result.getId());
        } else {
            System.out.println("请求失败，错误码:{}，错误信息:{}"+responseObj.getCode()+"12111"+ responseObj.getMessage());
        }
    }
}
